/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author edilson
 */
@Entity
@Table(name = "ListaAluno")
public class ListaAluno implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "avaliacao")
    private Boolean avaliacao;
    @Column(name = "dataAplicacao")
    @Temporal(TemporalType.DATE)
    private Date dataAplicacao;
    @JoinColumn(name = "aluno", referencedColumnName = "id")
    @ManyToOne
    private Aluno aluno;
    @ManyToOne
    @JoinColumn(name = "lista", referencedColumnName = "id")
    private Lista lista;
    @OneToMany(mappedBy = "listaAluno", cascade= CascadeType.ALL)
    private List<CorrecaoListaAluno> correcaoListaAlunos;

    public ListaAluno() {
    }

    public ListaAluno(Integer id) {
        this.id = id;
    }

    public ListaAluno(Integer id, Aluno aluno, Lista lista) {
        this.id = id;
        this.aluno = aluno;
        this.lista = lista;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Boolean getAvaliacao() {
        return avaliacao;
    }

    public void setAvaliacao(Boolean avaliacao) {
        this.avaliacao = avaliacao;
    }

    public Date getDataAplicacao() {
        return dataAplicacao;
    }

    public void setDataAplicacao(Date dataAplicacao) {
        this.dataAplicacao = dataAplicacao;
    }

    public Integer getNota() {
        int j = 0;
        for (CorrecaoListaAluno cla : getCorrecaoListaAlunos()) {
            if (cla.getNota() != null) {
                j += cla.getNota();
            }
        }

        return j;
    }

    public Aluno getAluno() {
        return aluno;
    }

    public void setAluno(Aluno aluno) {
        this.aluno = aluno;
    }

    public Lista getLista() {
        return lista;
    }

    public void setLista(Lista lista) {
        this.lista = lista;
    }

    public List<CorrecaoListaAluno> getCorrecaoListaAlunos() {
        return correcaoListaAlunos;
    }

    public void setCorrecaoListaAlunos(List<CorrecaoListaAluno> correcaoListaAlunos) {
        this.correcaoListaAlunos = correcaoListaAlunos;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ListaAluno)) {
            return false;
        }
        ListaAluno other = (ListaAluno) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.ListaAluno[id=" + id + "]";
    }
}
